{% assign data = section.settings %}
<div class="block_blogs container_wrapper">
    {% include 'title', title: data.block_title,detaile: data.block_detail,textAlgin: data.text_align %}
    <div class="blogs_content">
        {% assign blogs_ids = section.blocks | get_array_values: "blog" | get_array_values: "id" | join: "," %}
        {% if section.blocks.size %}
        {% get_blogs ids={blogs_ids} %}
        {% for block in section.blocks %}
        {% assign id = block.blog.id %}
        {% if blogs[id].size > 1 %}
        {% assign blog = blogs[id] %}
        <div class="blogs_item {% if forloop.first == true %}blogs_left{% else %}blogs_right{% endif %}">
            <article>
               <a href="/blogs/{{ blog.handle }}">
                  <div class="img_box">
										{%- if blog.image_alt == "" -%}
											{% assign blog_alt = blog | image_alt:'blog'   %}
										{%- else -%}
											{% assign blog_alt = blog.image_alt %}
										{%- endif -%}
                      <img data-sizes="auto" data-src="{{ blog.src | public_front_asset_url }}" src="{{ 'empty_loading.png' | public_asset_abs_dir_url }}"
                          alt="{{ blog_alt }}" />
                  </div>
                  <div class="text">
                      <div class="text_title">
                          <h2>
                            {{ blog.title }}
                          </h2>
                      </div>
                      <div class="time" data-date="{{blog.created_at}}" data-format="YYYY-mm-dd">{{ blog.published_at | date: "%Y-%m-%d" }}</div>
                      {% if blog.descript != '' %}
                      <div class="detail">{{ blog.descript }}</div>
                      {% endif %}
                  </div>
                </a>
            </article>
        </div>
        {% else %}
        <div class="blogs_item {% if forloop.first == true %}blogs_left{% else %}blogs_right{% endif %}">
            <article>
              <a href="javascirpt:;">
                <div class="img_box">
                    <img data-sizes="auto" data-src="" src="{{ 'empty.png' | public_asset_abs_dir_url }}"
                        alt="Please select blog" />
                </div>
                <div class="text">
                    <div class="text_title">
                        <h2>
                            Blog Title
                        </h2>
                    </div>
                    <div class="time">February 2022</div>
                    <div class="detail">Linen is one of the most common fabrics available these days, especially for
                        bath and bed fabrics. Discover several facts about it.</div>
                </div>
              </a>
            </article>
        </div>
        {% endif %}
        {% endfor %}
        {% endif %}
    </div>
    <div class="more">
		{% assign more_href = data.link | setUrlDataFrom:data_from %}
        {% include 'animation_btn', text: data.more_text,btnType: 'secondary_btn', url: more_href %}
    </div>
</div>
{% schema %}
{
	"tag": "",
	"class": "block_blogs",
	"icon": "icon-boke",
	"is_global": false,
	"name": {
		"zh_CN": "多选博客",
		"en_US": "Multiple Blogs"
	},
	"max_blocks": "2",
	"settings": [
		{
			"type": "card_header",
			"label": {
				"zh_CN": "设置",
				"en_US": "Settings"
			}
		},
		{
			"type": "card_select",
			"label": {
				"zh_CN": "标题对齐方式",
				"en_US": "Title alignment"
			},
			"default": "left",
			"id": "text_align",
			"option": [
				{
					"value": "left",
					"label": {
						"zh_CN": "居左",
						"en_US": "To the left"
					}
				},
				{
					"value": "center",
					"label": {
						"zh_CN": "居中",
						"en_US": "In the center"
					}
				},
				{
					"value": "right",
					"label": {
						"zh_CN": "居右",
						"en_US": "To the right"
					}
				}
			]
		},
		{
			"type": "card_input",
			"label": {
				"zh_CN": "标题",
				"en_US": "Title"
			},
			"id": "block_title",
			"default": ""
		},
		{
			"type": "card_text_editor",
			"label": {
				"zh_CN": "简短描述",
				"en_US": "Short description"
			},
			"id": "block_detail",
			"default": ""
		},
		{
			"type": "card_input",
			"label": {
				"zh_CN": "查看更多",
				"en_US": "See more"
			},
			"id": "more_text",
			"default": "Read More"
		},
		{
			"type": "card_page_link",
			"label": {
				"zh_CN": "查看更多链接",
				"en_US": "See more links"
			},
			"default": {
				"type": "14",
				"title": "",
				"url": "/blogs"
			},
			"id": "link"
		}
	],
	"blocks": [
		{
			"name": {
				"zh_CN": "博客",
				"en_US": "Blog"
			},
			"type": "blogs-item",
			"settings": [
				{
					"type": "card_blog",
					"id": "blog",
					"label": {
						"zh_CN": "博客",
						"en_US": "Blog"
					},
					"default": {
						"id": "",
						"title": ""
					}
				}
			]
		}
	],
	"default": {
		"settings": {
			"block_title": "Blogs",
			"block_detail": "",
			"more_text": "READ MORE",
			"text_align": "left",
			"link": {
				"type": "14",
				"title": "",
				"url": "/blogs"
			}
		},
		"blocks": [
			{
				"blog": {
					"id": "",
					"title": ""
				},
				"block_type": "blogs-item"
			},
			{
				"blog": {
					"id": "",
					"title": ""
				},
				"block_type": "blogs-item"
			},
			{
				"blog": {
					"id": "",
					"title": ""
				},
				"block_type": "blogs-item"
			}
		]
	}
}
{% endschema %}